﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOYOU.Framework.Config.Core
{
    //配置文件读取位置
    public class ConfigFactory
    {

        /// <summary>
        /// 获得配置
        /// </summary>
        /// <typeparam name="T">配置类泛型</typeparam>
        /// <returns>配置实例</returns>
        public static T GetConfig<T>() where T : class
        {
            return Config.GetConfigUnit(typeof(T)) as T;
        }


        #region 单件模式

        /// <summary>
        /// 单点实例
        /// </summary>
        private static ConfigFactory _Instance;

        /// <summary>
        /// 锁定（单点实例）
        /// </summary>
        private static object _lockPad = new object();

        private ConfigFactory()
        {

        }

        /// <summary>
        /// 获取服务工厂实例
        /// </summary>
        /// <returns>返回服务工厂实例</returns>
        public static ConfigFactory Instance()
        {
            if (_Instance == null)
            {
                lock (_lockPad)
                {
                    if (_Instance == null)
                    {
                        _Instance = new ConfigFactory();
                    }
                }
            }
            return _Instance;
        }

        #endregion
    }
}
